﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class AdvImageHtml : Portal.Interface.WebPart
    {
        protected global::FredCK.FCKeditorV2.FCKeditor FCKeditor1;
        public override string WebPartId
        {
            get
            {
                return "AdvImageHtml";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Cập nhật bài viết");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }


        public override void LoadSubControls(
                System.Web.UI.WebControls.PlaceHolder pl,
                System.Web.UI.Page Page, LoadParamCls LoadParamCls
            )
        {
            string AdvImageItemId = (string)System.Web.HttpContext.Current.Request["AdvImageItemId"];
            AdvImageItemCls AdvImageItemCls = new AdvImageBLL().CreateModelItem(Environments.ActiveLanguage, AdvImageItemId);
            FCKeditor1 = new FredCK.FCKeditorV2.FCKeditor();
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AdvImageHtml));

            string RetHtml =
                Portal.Environment.WebPartUtilities.AttachJavascript("Portal.CMS", "AdvImage.js") +
                             Portal.Environment.Environments.GetHeaderFormDialog(ResourceBLL.GetText(WebPartId,"AdvImageHtmlFormTitle","Cập nhật bài viết"))+
                             "      <table>" +
                             "          <tr>" +
                             "              <td colspan=2 class=cssTdFckEditor>";
            pl.Controls.Add(new System.Web.UI.LiteralControl(RetHtml));
            FCKeditor1.Height=400;
            FCKeditor1.Width = 780;
            FCKeditor1.Value = AdvImageItemCls.ContentHtml;
            FCKeditor1.BasePath = "fckeditor/";
            pl.Controls.Add(FCKeditor1);
            System.Web.HttpContext.Current.Session["AddHtmlFckEditor"] = FCKeditor1;
            RetHtml =
                             "</td>" +
                             "          </tr>" +
                             "          <tr>" +
                             "              <td class=cssCol1></td>" +
                             "              <td><input type=button class=cssSaveButton onclick=javascript:ClientSaveAdvImageItemHtml('" + AdvImageItemId + "'); value=\"" + ResourceBLL.GetText(WebPartId, "AdvImageHtmlSaveButton", "Ghi lại") + "\"><input type=button class=cssCancelButton onclick=javascript:window.close(); value=\"" + ResourceBLL.GetText(WebPartId, "AdvImageHtmlCancelButton", "Thoát") + "\"></td>" +
                             "          </tr>" +
                             "      </table>" + Portal.Environment.Environments.GetFooterFormDialog();
                             //"</div>" +
                             //"</div>";
            pl.Controls.Add(new System.Web.UI.LiteralControl(RetHtml));
        }



        [AjaxPro.AjaxMethod]
        public string ServerSideHtml(string AdvImageItemId, string Body)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                Body = System.Web.HttpUtility.HtmlDecode(Body);
                new AdvImageBLL().SaveContentHtml(null, AdvImageItemId, Body);
                return ResourceBLL.GetText(WebPartId,"MessageUpdateOk","Cập nhật thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

       
        [AjaxPro.AjaxMethod]
        public string GetInfoSaveMsg(string ActiveLanguage)
        {
            return ActiveLanguage + " - " + Language.ResourceBLL.GetText(WebPartId, "SaveOk", "cập nhật thành công!");
        }
    }
}